package com.gk.controller;

import com.eight.pojo.TbUser;
import com.eight.util.JWTTool;
import com.eight.util.WebFileUtil;
import com.eight.util.WebUtil;
import com.eight.vo.ComResult;
import com.eight.vo.TbUserVo;
import com.gk.service.TbUserService;

import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 返回用户信息创建fein接工作层
 * @author: GK
 * @date: 2023/2/27 10:33
 * @version:No1.0
 */
@RestController
@RequestMapping("/customer/tbClient/")
public class TbUserController {
    /**
     * 导入用户业务层
     */
    @Resource
    private TbUserService tbUserService;

    /**
     * 条件分页查询所有用户
     * @param pageIndex 当前页
     * @param pageSize 页中数据数量
     * @return 查询到的用户数据
     */
    @PostMapping("selectAll/{pageIndex}/{pageSize}")
    public ComResult selectAll(@RequestBody TbUserVo tbUserVo,@PathVariable Integer pageIndex,@PathVariable Integer pageSize){
        return tbUserService.selectAll(tbUserVo,pageIndex,pageSize);
    }

    /**
     * 根据账户和密码进行查询用户信息
     * @param password
     * @param username
     * @return
     */
    @GetMapping("selectOne/{username}/{password}")
    public TbUser selectOne(@PathVariable String username, @PathVariable String password){
        return tbUserService.selectOne(username,password);
    }

    /**
     * 查询所有用户
     * @return 查询到的用户
     */
   @PostMapping("selectAll")
    public List<TbUser> selectAll(){
        return tbUserService.selectUserAll();
   }


    /**
     * 根据账号查询用户信息
     * @param username 账号
     * @return 返回查到的用户信息
     */
    @PostMapping("selectUserFindUsername/{username}")
    public TbUser selectUserFindUsername(@PathVariable String username){
      return tbUserService.selectUserFindUsername(username);
    }


    /**
     * 查询所有用户信息
     * @return 返回地址和数量
     */
    @PostMapping("getUserList")
    public Map<String,Object> getUserList(){
     return    tbUserService.getUserList();
    }


    /**
     * 根据用户名查询用户信息
     * @return
     */
    @PostMapping("/selectTbUser")
    public TbUser selectTbUser(@RequestParam("token") String token){
        System.out.println(token);
        Map<String, Object> stringObjectMap = JWTTool.analyzeToken(token);
        String username = (String) stringObjectMap.get("username");
        return tbUserService.selectTbUser(username);
    }

    @PostMapping("updateUserMoney/{id}/{money}")//0失败1成功
    public int updateUserMoney(@PathVariable(value = "id") String username,@PathVariable(value = "money") Double money){
       return tbUserService.updateUserMoney(username,money);
    }


    /**
     * 根据账号减少金额
     * @param username 账号
     * @param money 金额
     * @return 1
     */
    @PostMapping("deleteMoney/{username}/{money}")
    public int deleteMoney(@PathVariable String username,@PathVariable Double money){
        return tbUserService.updateUserMoney(username,money);
    }




}
